/**
 * The WizardStep user-interface component class
 * @class syslib.ui.WizardStep
 * @author Gabriel Ricci
 */
syslib.ui.WizardStep = __class(syslib.ui.VisualTag, 
/** 
 * @lends syslib.ui.WizardStep
 */ 
{
	__parentTagName : "wizardpanel",
	
	id : null,
	name : null,
	title : null,
	selected : false, 

	next : null,
	previous : null,

	nextEnabled : true,
	previousEnabled : true,
	cancelEnabled : true,
	finishEnabled : false,
	
	onNext : false, 

	wizard : null, 

	prepare : function(){
		// get the tag attributes
		var attributes = this.__attributes;
		
		// check the needed attributes
		if(!__valid(attributes.name)){
			syslib.messages.error("syslib.ui.WizardStep.prepare(): You can't insert an unamed step on a wizard panel!");
			return false;
		}

		// set the class attributes
		this.id = (__valid(attributes.id)) ? attributes.id : syslib.element.generateID();
		this.name = attributes.name;
		this.title = (__valid(attributes.title)) ? attributes.title : "";
		this.selected = (__valid(attributes.selected)) ? true : false;
		this.next = null;
		this.previous = null;
		this.cancelEnabled = (__valid(attributes.cancel) && attributes.cancel == "false") ? false : true;
		this.onNext = (__valid(attributes.onnext))  ? attributes.onnext : false;
		this.finishEnabled = (__valid(attributes.finish) && attributes.finish == "true")  ? true : false;
		this.wizard = this.__parent;

		if(!__valid(attributes.next)){
			this.nextEnabled = false;
		} else {
			this.next = attributes.next; 
			this.nextEnabled = true;
		}
		if(!__valid(attributes.previous)){
			this.previousEnabled = false;
		} else {
			this.previous = attributes.previous; 
			this.previousEnabled = true;
		}
		
		
		// return
		return true;
	},

	execute : function(){
		// create the structure
		var structure = ["div", 
	        ["div", {"class" : "wizard-step-body"}, this.__innerHTML], 
	        ["div", {"style" : "display: none", "innerName" : "title"}, this.title]
		];
		
		// create the object
		var step = this.createDOM(structure);

		// return
		return step;
	},

	finalize : function(){
		// add this step to the wizard
		this.wizard.addStep(this);
	},
	
	onEnterBody : function(){
		// check if this step needs to be selected
		if(__valid( this.selected )){
			this.wizard.selectStep(this.name);
		}
	}, 

	onEvent : function(eventName){
		// format the event name
		var eventName = "on" + eventName;
		
		// check if this event exists
		if(__valid(this.__attributes[eventName])){
			return eval(this.__attributes[eventName]);
		} else {
			return true;
		}
	}
});